package com.lovo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.bean.SysCommodity;

import com.lovo.entity.SysCommodityEntity;
import com.lovo.mapper.SysCommodityMapper;
import com.lovo.service.ISysCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-09-17
 */
@RestController
@RequestMapping("qd/commodity")
public class SysCommodityController {


    @Autowired
    ISysCommodityService sysCommodityService;

    @Autowired
    SysCommodityMapper commodityMapper;

    @GetMapping("findUpGoods")
    public IPage<SysCommodity> findShelfProduct(Integer pageNo, String type) {

        return sysCommodityService.findShelfProduct(pageNo, type);
    }

    @GetMapping("listings/{sysCommodityId}/{sellPrice}/{imgPath}/{info}")
    public String listings(@PathVariable("sysCommodityId") Integer sysCommodityId,
                           @PathVariable("sellPrice") Integer sellPrice,
                           @PathVariable("imgPath") String imgPath,
                           @PathVariable("info") String info) {

        sysCommodityService.listings(sysCommodityId, sellPrice, imgPath, info);
        return "ok";
    }

    @GetMapping("findAllCommodityEntityByInfo")
    public List<SysCommodityEntity> findAllCommodityEntityByInfo(String info) {
        return sysCommodityService.findAllCommodityEntityByInfo(info);
    }

    @GetMapping("findAllType")
    public Set<String> findAllType() {
        return commodityMapper.findAllType();
    }

    @PutMapping("downProduct/{productId}")
    public void downProduct(@PathVariable("productId") Integer productId) {
        sysCommodityService.downProduct(productId);

    }

}
